<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    body,
    html {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        background-color: rgb(240, 108, 122);

    }


    .headbox {
        display: flex;
    }

    .textHeader {
        /* width: 100%; */
        height: 20px;
        color: #ffff;
        font-size: 16px;
        text-align: center;
        margin-top: 10px;
        margin-left: 27%;
        /* flex: 1; */

    }

    .leftlabel img {
        width: 20px;
        height: 20px;
        margin-top: 10px;
        margin-left: 30px;
    }

    .home {
        width: 100%;
        height: 200px;
        position: relative;
    }

    .centerhome {
        width: 100px;
        height: 100px;
        position: absolute;
        left: 50%;
        top: 50%;
        margin-left: -50px;
        margin-top: -50px;

    }

    .centerhome img {
        width: 100px;
        height: 100px;

    }

    .centerinput {
        width: 100%;
        height: 450px;
        position: relative;
        cursor: pointer;

    }

    .centerinput input {
        width: 70%;
        height: 40px;
        background-color: rgb(244, 124, 136);
        border-radius: 25px;
        /* position: absolute;
        left: 50%; */
        /* top: 50%; */
        margin-left: 50px;
        margin-top: 20px;
        border: none;
        cursor: pointer;

    }

    #whiwtebg {
        background-color: #ffff;
        color: rgb(240, 108, 122);

    }

    .msgbox {
        width: 100%;
        height: 40px;
        text-align: center;
        margin-top: 6px;
    }

    .msg {
        width: 100%;
        height: 30px;
        color: #ffff;
        text-align: center;
        font-size: 14px;
        text-decoration: none;
    }

    .color {
        color: floralwhite;
        text-indent: 15px;
        cursor: pointer;

    }
</style>

<body>
    <header class="headbox">
        <div class="leftlabel">
            <img src="../img/向左_返回.png">
        </div>
        <div class="textHeader">注册账号</div>
    </header>
    <main>
        <div class="home">
            <div class="centerhome">
                <img src="../img/house.png">
            </div>
        </div>
        <div class="centerinput">
            <form id="registerForm" action="./登录.html" method="post">
                <input type="text" placeholder="请输入账号" class="color">
                <input type="password" placeholder="请输入密码" class="color">
                <input type="password" placeholder="请再次输入密码" class="color">
                <input type="submit" value="立即注册" id="whiwtebg"><br>
            </form>
            <div class="msgbox">
                <span class="msg" id="successMsg" style="display: none;">注册成功！</span>
                <a class="msg" href="./登录.html">已有账号立即登录</a>
            </div>
        </div>
    </main>
    <footer></footer>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.5.0/axios.js"></script>
    <script>


        let registerForm = document.getElementById('registerForm');
        let successMsg = document.getElementById('successMsg');

        registerForm.addEventListener('submit', function (event) {
            event.preventDefault();
            // // 模拟注册成功
            // successMsg.style.display = 'block';
            // 延时1秒后跳转到登录页面
            setTimeout(function () {
                if (registerForm.elements[0].value !== '' && registerForm.elements[1].value !== '') {
                    axios.post('http://8.137.157.16:9000/user/register', { account: registerForm.elements[0].value, password: registerForm.elements[1].value })
                        .then(function (res) {
                            console.log(res);
                            window.location.href = './登录.html';
                            console.log(res.data);

                        }).catch(function (err) {
                            console.log(err);
                        })


                } else {
                    alert('账号和密码均不能为空！');

                }
            }, 1000);
        });



    </script>
</body>

</html>